package com.hzystudynote;

/** @author ASUS */
public class MyThread {
  public static void main(String[] args) {
    System.out.println("主线程ID:" + Thread.currentThread().getId());
    Tests thread1 = new Tests("thread1");
    thread1.start();
    Tests thread2 = new Tests("thread2");
    thread2.start();

    System.out.println("开始进行统计");
    ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
    int counter = currentGroup.activeCount();
    Thread[] threads = new Thread[counter];
    currentGroup.enumerate(threads);
    for (Thread item : threads) {
      System.out.printf("%s+%d\n", item.getName(), item.getId());
    }
  }
}

class Tests extends Thread {
  private final String name;

  public Tests(String name) {
    this.name = name;
  }

  @Override
  public void run() {
    System.out.println("name:" + name + " 子线程ID:" + Thread.currentThread().getId());
  }
}
